<script type="text/javascript"><!--//--><![CDATA[//><!--

	var grid_reload = function(){
		$('#datagrid').datagrid('reload', $('#fm_search').serializeObject());
	};
	
	
	
    $(document).ready(function() {
		$('#tb').setupForm([
			{ name: 'type', type: 'text', size: 'short', data:[
						{value:'I', display:'Inbox'},
						{value:'S', display:'Sent Box'}						
					]}
		], <?php echo json_encode($data); ?>);
		
		
        $('#datagrid').datagrid({  
			url:gs_path+'/'+controller+'/getdata', 
			queryParams: $('#fm_search').serializeObject(),
			height:400,
			pagination:true,
			singleSelect:true,
			columns:[[
				{ field : 'from',title:'From',width:100, sortable:true },
				{ field : 'to',title:'To',width:200, sortable:true },							
				{ field : 'subject',title:'Subject',width:200, sortable:true },							
				{ field : 'message',title:'Message',width:500, sortable:true }
			]],
			rowStyler:function(index,row,css){
				if (row.read_status=='0'){
					return 'background-color:#6293BB;color:#fff;font-weight:bold;';
				}
			}
		});

        // Set Action Button
        var buttons = [
                        // ----- >> Add Button
                        { label: 'Add', icon: 'add', onclick: function() {
                            loadPage( '/' + controller + '/create/');
                        }},
                        
                        // ----- >> Edit Button
					    { label: 'View', icon: 'edit', onclick: function() {
					       var oSel = $('#datagrid').datagrid('getSelected');
					        if (oSel == null) {
					            alert('Please select row!'); 
					        } else {
								loadPage( '/' + controller + '/edit/?id='+urlencode(oSel.id));
					        }  
					    }}
                        ];
        setAction(buttons);

    });
//--><!]]></script>
<div id="tb" style="padding:5px;height:auto">
    <div>
        <form id="fm_search" onsubmit="grid_reload(); return false;">
        	<table class="tb_form" style="margin-bottom:0px">
			<tr>
            	<td width="100">Type</td>
                <td><input type="text" id="type" name="type" class="textfield medium" />
                </td>
            </tr>
            <tr>
            	<td width="100">Keyword</td>
                <td><input type="text" id="keyword" name="keyword" class="textfield medium" />
                	<a href="#" class="easyui-linkbutton" iconCls="icon-search" onclick="grid_reload(); return false;">Search</a>
                </td>
            </tr>
            </table>
        </form>
    </div>
</div>

<div id="datagrid" toolbar="#tb"></div>
